﻿using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using EnvDTE80;

namespace FXCopAddIn.Classes
{
    public sealed class BuildOutput
    {
        #region Fields

        private Window _window;
        private OutputWindow _outputWindow;
        private OutputWindowPane _buildPane;
        private DTE2 _applicationObject;

        #endregion

        #region Construtor

        public BuildOutput(DTE2 applicationObject)
        {
            _applicationObject = applicationObject;
            _window = _applicationObject.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
            _outputWindow = (OutputWindow)_window.Object;
            _buildPane = _outputWindow.OutputWindowPanes.Item("Build");
        }

        #endregion

        #region Public Methods

        public void EscreveOutput(string mensagem)
        {
            EscreveOutput(mensagem, false);
        }

        public void EscreveOutput(string mensagem, bool limpaOutput)
        {
            if (_applicationObject.ActiveWindow != _window)
                _window.Activate();

            if (_outputWindow.ActivePane != _buildPane)
                _buildPane.Activate();

            if (limpaOutput)
                _buildPane.Clear();

            _buildPane.OutputString(mensagem);
        }

        #endregion
    }
}
